package com.cate.controller.admin;

import com.cate.exception.BusinessException;
import com.cate.oss.MinioTemplate;
import com.cate.oss.OssFile;
import com.cate.result.RestResponse;
import com.cate.result.SystemCode;
import com.cate.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import okhttp3.internal.http2.ErrorCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @CreateTime: 2023/7/29
 * @Author: <==lhd==>
 * @Description:
 */
@RestController
@RequestMapping("/admin/common")
@Api(tags = "通用接口")
public class CommonController {

    @Autowired
    MinioTemplate minioTemplate;


    @PostMapping("/upload")
    @ApiOperation("上传文件")
    public RestResponse upload(@RequestPart("file") MultipartFile file) throws IOException {
        String url = null;
        url =  minioTemplate.putObjectToUrl(file);

        if(!url.isEmpty())
            return ResultUtil.success(url);
        else
            throw new BusinessException(SystemCode.REQUEST_ERROR, "上传失败");
    }
}
